package cn.kgc.day05.mapper;

import cn.kgc.day05.entity.Emp;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author: 课工场
 * @since 2023/9/26
 * mybatis框架中使用注解完成sql语句的编写
 * @Select   实现查询语句的编写
 *  @Results(id="empMap")   id的值可以用于后续结果集映射的引用
 *  @ResultMap("empMap")    value="empMap"  引用id为empMap的结果集映射
 */
@CacheNamespace   // 开启二级缓存
public interface EmpMapper {

    @Select("select *  from emp")
    @ResultMap("empMap")
    List<Emp>  getList();

    @Select("select *  from emp where id = #{id}")
    @Results(id="empMap",value = {
            @Result(column = "id",property = "id"),
            @Result(column = "ename",property = "empName"),
            @Result(column = "age",property = "age"),
            @Result(column = "deptno",property = "deptno")
    })
    Emp  getById(Integer id);


    @Insert("insert into emp (ename,age,deptno)values(#{empName},#{age},#{deptno})")
    Integer  addEmp(Emp emp);


    @Update("update emp set age = #{age} where id = #{id}")
    Integer  updateEmp(Emp emp);


    @Delete("delete from emp where id = #{id}")
    Integer deleteEmp(Integer id);

    List<Emp>  getPage(@Param("start") Integer start ,@Param("limit") Integer limit);

    Integer  getTotal();
}
